/*
 *  POJ2251: Dungeon Master
 */

/*-------- Includes --------*/
#include <iostream>
#include <queue>

using namespace std;

/*-------- Types --------*/
struct Point {
    int L, R, C;
    int D;      // depth
public:
    Point() {}
    Point(int l, int r, int c, int d) : L(l), R(r), C(c), D(d) {}
};

/*-------- Global Variables --------*/
bool maze[32][32][32];
int nL, nR, nC;

Point S, E;

/*-------- Function Prototypes --------*/

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    char cstr[32];

    while (cin >> nL >> nR >> nC && nL) {
        for (int i = 0; i < nL; i++) {
            for (int j = 0; j < nR; j++) {
                cin >> cstr;

                for (int k = 0; k < nC; k++) {
                    if      (cstr[k] == '#') { maze[i][j][k] = false;     }
                    else if (cstr[k] == '.') { maze[i][j][k] = true;      }
                    else if (cstr[k] == 'S') { S.L = i; S.R = j; S.C = k; }
                    else                     { E.L = i; E.R = j; E.C = k; }
                }
            }
            // skip blank line
            cin.get();
        }

        bool isFound = false;;

        Point        pt;
        queue<Point> que;

        S.D = 0;
        que.push(S);
        maze[S.L][S.R][S.C] = false;
        maze[E.L][E.R][E.C] = true;

        while (!que.empty()) {
            pt = que.front(); que.pop();

            // base case: find the exit
            if (pt.L == E.L && pt.R == E.R && pt.C == E.C) { isFound = true; break; }

            if (pt.L > 0 && maze[pt.L - 1][pt.R][pt.C]) {
                que.push(Point(pt.L - 1, pt.R, pt.C, pt.D + 1));
                maze[pt.L - 1][pt.R][pt.C] = false;
            }

            if (pt.L + 1 < nL && maze[pt.L + 1][pt.R][pt.C]) {
                que.push(Point(pt.L + 1, pt.R, pt.C, pt.D + 1));
                maze[pt.L + 1][pt.R][pt.C] = false;
            }

            if (pt.R > 0 && maze[pt.L][pt.R - 1][pt.C]) {
                que.push(Point(pt.L, pt.R - 1, pt.C, pt.D + 1));
                maze[pt.L][pt.R - 1][pt.C] = false;
            }

            if (pt.R + 1 < nR && maze[pt.L][pt.R + 1][pt.C]) {
                que.push(Point(pt.L, pt.R + 1, pt.C, pt.D + 1));
                maze[pt.L][pt.R + 1][pt.C] = false;
            }

            if (pt.C > 0 && maze[pt.L][pt.R][pt.C - 1]) {
                que.push(Point(pt.L, pt.R, pt.C - 1, pt.D + 1));
                maze[pt.L][pt.R][pt.C - 1] = false;
            }

            if (pt.C + 1 < nC && maze[pt.L][pt.R][pt.C + 1]) {
                que.push(Point(pt.L, pt.R, pt.C + 1, pt.D + 1));
                maze[pt.L][pt.R][pt.C + 1] = false;
            }
        }

        // print result
        if (isFound)
            cout << "Escaped in " << pt.D << " minute(s)." << endl;
        else
            cout << "Trapped!" << endl;
    }

    return 0;
}

/*-------- Functions --------*/

